package com.dmooo.yxmmerchant.adapter;

import android.support.annotation.Nullable;
import android.text.Html;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.common.util.SPUtils;
import com.dmooo.yxmmerchant.R;
import com.dmooo.yxmmerchant.common.Config;
import com.dmooo.yxmmerchant.domain.GoodsOrderListBean;
import com.dmooo.yxmmerchant.view.ui.UserInfoActivity;

import java.util.List;

public class MyGoodsOrderAdapter extends BaseQuickAdapter<GoodsOrderListBean.Item, BaseViewHolder> {
    public MyGoodsOrderAdapter(int layoutResId, @Nullable List<GoodsOrderListBean.Item> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder holder, final GoodsOrderListBean.Item item) {
        holder.setText(R.id.txt_order_num, "订单编号:" + item.order_num);
        holder.getView(R.id.txt_pay).setVisibility(View.GONE);
        holder.getView(R.id.txt_reason).setVisibility(View.GONE);
        holder.getView(R.id.txt_cancle).setVisibility(View.GONE);
        holder.getView(R.id.txt_pat_mother).setVisibility(View.VISIBLE);
        holder.getView(R.id.txt_apply_cancle).setVisibility(View.GONE);
        holder.getView(R.id.txt_ok_shouhuo).setVisibility(View.GONE);
        holder.getView(R.id.txt_comment).setVisibility(View.GONE);
        holder.getView(R.id.txt_danhao).setVisibility(View.GONE);
        holder.getView(R.id.txt_wuliu).setVisibility(View.GONE);
        holder.getView(R.id.txt_shezhi).setVisibility(View.GONE);
        holder.getView(R.id.txt_change).setVisibility(View.GONE);
        holder.getView(R.id.txt_goods_code).setVisibility(View.VISIBLE);
        holder.setText(R.id.txt_goods_code, "订货号:" + item.goods_code);
        holder.setText(R.id.txt_user_name, "用户:" + item.user_account);
        holder.getView(R.id.txt_user_name).setVisibility(View.VISIBLE);
        if (item.r_phone == null || "".equals(item.r_phone)) {
            holder.getView(R.id.txt_user_name2).setVisibility(View.GONE);
        } else {
            holder.getView(R.id.txt_user_name2).setVisibility(View.VISIBLE);
            holder.setText(R.id.txt_user_name2, "中间商:" + item.r_phone);
        }
        if(mContext instanceof UserInfoActivity){
            holder.getView(R.id.ll_ri).setVisibility(View.GONE);
        }else{
            holder.getView(R.id.ll_ri).setVisibility(View.VISIBLE);

        }
        if (!"1".equals(item.status))
            switch (item.pay_method) {
                case Config.PAY_OFFLINE:
                    holder.setText(R.id.txt_pat_mother, "支付方式: 公司转账");
                    break;
                case Config.PAY_DELIVERY:
                    holder.setText(R.id.txt_pat_mother, "支付方式: 货到付款");
                    break;
                case Config.PAY_BALANCE:
                    holder.setText(R.id.txt_pat_mother, "支付方式: 余额支付");
                    break;
                case Config.PAY_ZFB:
                    holder.setText(R.id.txt_pat_mother, "支付方式: 支付宝支付");
                    break;
                case Config.PAY_WXPAY:
                    holder.setText(R.id.txt_pat_mother, "支付方式: 微信支付");
                    break;
            }
        switch (item.status) {
            case "1":
                if (Config.PAY_OFFLINE.equals(item.pay_method)) {
                    holder.setText(R.id.txt_status, "待确认收款");
                    holder.setText(R.id.txt_pat_mother, "支付方式: 公司转账");
                    TextView tx = holder.getView(R.id.txt_reason);
                    tx.setVisibility(View.VISIBLE);
                    tx.setText("订单状态: 该订单为公司转账,待确认收款");
                    ((TextView) holder.getView(R.id.txt_comment)).setText("确认收款");
                    tx.setTextColor(mContext.getResources().getColor(R.color.colorPrimary));
                    holder.getView(R.id.txt_comment).setVisibility(View.VISIBLE);
//                    holder.getView(R.id.txt_pay).setVisibility(View.VISIBLE);
//                    holder.getView(R.id.txt_cancle).setVisibility(View.VISIBLE);
                } else if (Config.PAY_DELIVERY.equals(item.pay_method)) {
                    holder.setText(R.id.txt_pat_mother, "支付方式: 货到付款");
                    holder.setText(R.id.txt_status, "待确认发货");
                    TextView tx = holder.getView(R.id.txt_reason);
                    tx.setVisibility(View.VISIBLE);
                    tx.setText("订单状态: 该订单为货到付款，待发货 ");
                    tx.setTextColor(mContext.getResources().getColor(R.color.colorPrimary));
                    ((TextView) holder.getView(R.id.txt_comment)).setText("发货");
                    holder.getView(R.id.txt_comment).setVisibility(View.VISIBLE);
                } else {
                    holder.getView(R.id.txt_pat_mother).setVisibility(View.GONE);
                    holder.setText(R.id.txt_status, "待付款");
                }
                if ("1".equals(SPUtils.get(mContext, Config.LOGIN_TYPE, "1").toString()) || Config.AUTH.contains("14") || Config.AUTH.contains("15") || Config.AUTH.contains("10"))
                    holder.getView(R.id.txt_change).setVisibility(View.VISIBLE);
                if ("Y".equals(item.is_inquiry)) {
//                        if("".equals(Config.ADMIN_ID)){
//                            if(Config.AUTH.contains("14")||Config.AUTH.contains("15")||Config.AUTH.contains("10"))
//                                holder.getView(R.id.txt_change).setVisibility(View.VISIBLE);
//                        }else{
//                            holder.getView(R.id.txt_change).setVisibility(View.VISIBLE);
//                        }
                    if (Double.valueOf(item.allprice) <= 0) {
                        holder.getView(R.id.txt_shezhi).setVisibility(View.GONE);
                    } else {
                        if ("2".equals(item.is_partial)) {
                            holder.getView(R.id.txt_shezhi).setVisibility(View.VISIBLE);
                        } else {
                            TextView tx = holder.getView(R.id.txt_reason);
                            tx.setVisibility(View.VISIBLE);
                            tx.setText("分阶段支付,待买家支付第一阶段 ");
                            tx.setTextColor(mContext.getResources().getColor(R.color.colorPrimary));
                        }
                    }
                } else {
                    if ("2".equals(item.is_partial)) {
                        holder.getView(R.id.txt_shezhi).setVisibility(View.VISIBLE);
                    } else {
                        TextView tx = holder.getView(R.id.txt_reason);
                        tx.setVisibility(View.VISIBLE);
                        tx.setText("分阶段支付,待买家支付第一阶段 ");
                        tx.setTextColor(mContext.getResources().getColor(R.color.colorPrimary));
                    }
                }
//                holder.getView(R.id.txt_pay).setVisibility(View.VISIBLE);
//                holder.getView(R.id.txt_cancle).setVisibility(View.VISIBLE);
                break;
            case "2":
                holder.setText(R.id.txt_status, "待发货");
                if (Config.PAY_DELIVERY.equals(item.pay_method)) {
                    TextView tx = holder.getView(R.id.txt_reason);
                    tx.setVisibility(View.VISIBLE);
                    tx.setText("订单状态: 该订单为货到付款，待发货");
                    tx.setTextColor(mContext.getResources().getColor(R.color.colorPrimary));
                } else if (Config.PAY_OFFLINE.equals(item.pay_method)) {
                    TextView tx = holder.getView(R.id.txt_reason);
                    tx.setVisibility(View.VISIBLE);
                    tx.setText("订单状态: 该订单为公司转账,已确认收款");
                    tx.setTextColor(mContext.getResources().getColor(R.color.colorPrimary));
                }
                if ("2".equals(item.is_partial)) {
                } else {
                    TextView tx = holder.getView(R.id.txt_reason);
                    tx.setVisibility(View.VISIBLE);
                    tx.setText("该订单是分阶段支付");
                    tx.setTextColor(mContext.getResources().getColor(R.color.colorPrimary));
                }
                holder.getView(R.id.txt_apply_cancle).setVisibility(View.VISIBLE);
                break;
            case "3":
                if (Config.PAY_DELIVERY.equals(item.pay_method)) {
                    TextView tx = holder.getView(R.id.txt_reason);
                    tx.setVisibility(View.VISIBLE);
                    tx.setText("备注: 该订单为货到付款,已发货");
                    tx.setTextColor(mContext.getResources().getColor(R.color.colorPrimary));
                } else if (Config.PAY_OFFLINE.equals(item.pay_method)) {
                    TextView tx = holder.getView(R.id.txt_reason);
                    tx.setVisibility(View.VISIBLE);
                    tx.setText("备注: 该订单为公司转账,已发货");
                    tx.setTextColor(mContext.getResources().getColor(R.color.colorPrimary));
                }
                if ("2".equals(item.is_partial)) {
                } else {
                    TextView tx = holder.getView(R.id.txt_reason);
                    tx.setVisibility(View.VISIBLE);
                    tx.setText("该订单是分阶段支付");
                    tx.setTextColor(mContext.getResources().getColor(R.color.colorPrimary));
                }
                holder.setText(R.id.txt_status, "待收货");
                holder.getView(R.id.txt_wuliu).setVisibility(View.VISIBLE);
//                holder.setText(R.id.txt_reason,"快递单号:"+orderDetailBean.express_number);
                break;
            case "4":
                holder.setText(R.id.txt_status, "待评价");
                if ("2".equals(item.is_partial)) {
                } else {
                    TextView tx = holder.getView(R.id.txt_reason);
                    tx.setVisibility(View.VISIBLE);
                    tx.setText("该订单是分阶段支付");
                    tx.setTextColor(mContext.getResources().getColor(R.color.colorPrimary));
                }
                break;
            case "5":
                holder.setText(R.id.txt_status, "已完成");
                if ("2".equals(item.is_partial)) {
                } else {
                    TextView tx = holder.getView(R.id.txt_reason);
                    tx.setVisibility(View.VISIBLE);
                    tx.setText("该订单是分阶段支付");
                    tx.setTextColor(mContext.getResources().getColor(R.color.colorPrimary));
                }
                break;
            case "6":
                holder.setText(R.id.txt_status, "申请退款中...");
                holder.getView(R.id.txt_reason).setVisibility(View.VISIBLE);
                holder.setText(R.id.txt_reason, "退款原因: " + item.drawback_reason);
                holder.getView(R.id.txt_pay).setVisibility(View.VISIBLE);
                break;
            case "7":
                if (item.refund_express_number != null && !"".equals(item.refund_express_number)) {
                    holder.setText(R.id.txt_status, "已退货，待退款...");
                    holder.getView(R.id.txt_wuliu).setVisibility(View.VISIBLE);
                    holder.getView(R.id.txt_ok_shouhuo).setVisibility(View.VISIBLE);
                } else {
                    holder.setText(R.id.txt_status, "待退货...");
//                    holder.getView(R.id.txt_danhao).setVisibility(View.VISIBLE);
                }
                break;
            case "8":
                holder.setText(R.id.txt_status, "拒绝退款");
                holder.getView(R.id.txt_reason).setVisibility(View.VISIBLE);
                holder.setText(R.id.txt_reason, "拒绝原因: " + item.drawback_refuse_reason);
                break;
            case "9":
                holder.setText(R.id.txt_status, "已退款");
                break;
        }
        ImageView img = holder.getView(R.id.img_shop);
        Glide.with(mContext).load(Config.APP_INTERFACE_BASE_URL + item.img).error(R.mipmap.defaultpicture_classify).dontAnimate().into(img);
        holder.setText(R.id.txt_name, item.goods_name);
        holder.setText(R.id.txt_num, "共" + item.num + "件  总额:" + Config.RMB + item.allprice);
        holder.setText(R.id.txt_price, Config.RMB + item.price);
        if ("Y".equals(item.is_inquiry)) {
            holder.setText(R.id.txt_price, Config.RMB + item.price + "(询价单)");
        }
        holder.setText(R.id.txt_attribute, item.sku == null ? "" : Html.fromHtml(item.sku).toString());
        holder.addOnClickListener(R.id.txt_cancle).addOnClickListener(R.id.txt_pay).addOnClickListener(R.id.txt_apply_cancle)
                .addOnClickListener(R.id.txt_ok_shouhuo).addOnClickListener(R.id.txt_change).addOnClickListener(R.id.txt_shezhi).addOnClickListener(R.id.txt_wuliu).addOnClickListener(R.id.txt_danhao).addOnClickListener(R.id.txt_comment);
    }
}
